#include <stdio.h>  
  
int month[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};  
  
int month2[13] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};  
  
int judge(int y) {  
    if (y % 4 == 0) {  
        if (y % 100 == 0) {  
            if (y % 400 != 0)  
                return 0;  
        }  
        return 1;  
    }  
    return 0;  
}  
int main(int argc, char **argv) {  
    int n, y, m, d, x = 0;  
    if (scanf("%d%d%d%d", &y, &m, &d, &n));  
    x += 400 * (n / 146097);  
    n %= 146097;  
    x += 100 * (n / 36524);  
    n %= 36524;  
    x += 4 * (n / 1461);  
    n %= 1461;  
    y += x;  
  
  
    while (n-- != 0) {  
        d++;  
        if (judge(y) == 1) {  
            if (d > month2[m]) {  
                d = 1;  
                m++;  
            }  
        } else if (d > month[m]) {  
            d = 1;  
            m++;  
        }  
        if (m > 12) {  
            y++;  
            m = 1;  
        }  
    }  
    printf("%d.%d.%d\n", y, m, d);  
    return 0;  
}  